package com.atguigu.binarysearch;

/**
 * @author xgc
 * @create 2021-07-22 10:54
 * 双重检查锁（提高同步锁的效率）
 */
public class Singleton4 {
    //私有构造
    private Singleton4(){}

    //初始值为null
    private static Singleton4 singleton4 = null;

    //双从检查锁
    public static Singleton4 getInstance(){
        if (singleton4 == null){
            synchronized (Singleton4.class){
                if (singleton4 == null){
                    singleton4 = new Singleton4();
                }
            }
        }
        return singleton4;
    }
}
